﻿using System;

using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;

namespace HandRise.MBHOP.Controls
{
    public class DataList : Control
    {
        #region 属性


        private Object dataSource = null;
        /// <summary>
        /// 数据源

        /// </summary>
        public Object DataSource
        {
            get
            {
                return dataSource;
            }
            set
            {
                dataSource = value;
                //DataBind();
            }
        }

        string displayMember = "";
        /// <summary>
        /// 要显示的属性

        /// </summary>
        public string DisplayMember
        {
            get
            {
                return displayMember;
            }
            set
            {
                displayMember = value;
            }
        }

        string keyMember = "";
        /// <summary>
        /// 主键
        /// </summary>
        public string KeyMember
        {
            get
            {
                return keyMember;
            }
            set
            {
                keyMember = value;
            }
        }

        bool isRadio = true;
        /// <summary>
        /// 是否单选

        /// </summary>
        public bool IsRadio
        {
            get
            {
                return isRadio;
            }
            set
            {
                isRadio = value;
            }
        }

        /// <summary>
        /// 当前选择的项的索引
        /// </summary>
        object selectItem = null;
        public object SelectItem
        {
            get
            {
                return selectItem;
            }
        }

        Color itemBackColor = Color.White;
        /// <summary>
        /// 弹起时的按钮背景色

        /// </summary>
        public Color ItemBackColor
        {
            set
            {
                itemBackColor = value;
            }
            get
            {
                return itemBackColor;
            }
        }

        Color selectItemBackColor = Color.LightBlue;
        /// <summary>
        /// 按下时的按钮背景色

        /// </summary>
        public Color SelectItemBackColor
        {
            set
            {
                selectItemBackColor = value;
            }
            get
            {
                return selectItemBackColor;
            }
        }

        /// <summary>
        /// 文本的字体

        /// </summary>
        public override Font Font
        {
            get
            {
                return new Font("雅黑", ItemFontSize, FontStyle.Regular);
            }
        }

        /// <summary>
        /// 文本的字体

        /// </summary>
        private Font ItemFont
        {
            get
            {
                if (ItemFontSize <= 0)
                    return new Font("雅黑", 1, FontStyle.Regular);
                else
                    return new Font("雅黑", ItemFontSize, FontStyle.Regular);
            }
        }

        /// <summary>
        /// 按下时文本的字体
        /// </summary>
        private Font SelectItemFont
        {
            get
            {
                if (SelectItemFontSize <= 0)
                    return new Font("雅黑", 1, FontStyle.Regular);
                else
                    return new Font("雅黑", SelectItemFontSize, FontStyle.Regular);
            }
        }

        int itemFontSize = 12;
        /// <summary>
        /// 弹起时的文本字号
        /// </summary>
        [DefaultValue(12)]
        public int ItemFontSize
        {
            set
            {
                itemFontSize = value;
            }
            get
            {
                return itemFontSize;
            }
        }

        int selectItemFontSize = 12;
        /// <summary>
        /// 按下时的文本字号
        /// </summary>
        [DefaultValue(12)]
        public int SelectItemFontSize
        {
            set
            {
                selectItemFontSize = value;
            }
            get
            {
                return selectItemFontSize;
            }
        }

        Color itemForeColor = Color.Black;
        /// <summary>
        /// 弹起时的文本颜色
        /// </summary>

        public Color ItemForeColor
        {
            set
            {
                itemForeColor = value;
            }
            get
            {
                return itemForeColor;
            }
        }

        Color selectItemForeColor = Color.White;
        /// <summary>
        /// 按下时的文本颜色
        /// </summary>
        public Color SelectItemForeColor
        {
            set
            {
                selectItemForeColor = value;
            }
            get
            {
                return selectItemForeColor;
            }
        }

        int leftSpace = 0;
        /// <summary>
        /// 文本的左边距
        /// </summary>
        public int LeftSpace
        {
            get
            {
                return leftSpace;
            }
            set
            {
                if (value < 0)
                    value = 0;
                leftSpace = value;
            }
        }

        int rightSpace = 0;
        /// <summary>
        /// 文本的右边距
        /// </summary>
        public int RightSpace
        {
            get
            {
                return rightSpace;
            }
            set
            {
                if (value < 0)
                    value = 0;
                rightSpace = value;
            }
        }

        int pageSize = 4;
        /// <summary>
        /// 每页的数量

        /// </summary>
        [DefaultValue(4)]
        public int PageSize
        {
            get
            {
                return pageSize;
            }
            set
            {
                if (value < 0)
                    value = 0;
                pageSize = value;
            }
        }

        int pageCount = 0;
        /// <summary>
        /// 总页数

        /// </summary>
        public int PageCount
        {
            get
            {
                return pageCount;
            }
        }

        internal int pageIndex = 0;
        /// <summary>
        /// 当前页索引

        /// </summary>
        public int PageIndex
        {
            get
            {
                return pageIndex;
            }
        }

        int itemMargin = 4;
        /// <summary>
        /// 项的间距
        /// </summary>
        [DefaultValue(4)]
        public int ItemMargin
        {
            get
            {
                return itemMargin;
            }
            set
            {
                if (value < 0)
                    value = 0;
                itemMargin = value;
            }
        }

        int iconWidth = 0;
        /// <summary>
        /// 图标框长度

        /// </summary>
        public int IconWidth
        {
            get
            {
                return iconWidth;
            }
            set
            {
                if (value < 0)
                    value = 0;
                iconWidth = value;
            }
        }

        //按下的对象的标识列表
        private List<string> selectItemKey = new List<string>();
        /// <summary>
        /// 选中的项的标识列表

        /// </summary>
        public List<string> SelectItemKey
        {
            get
            {
                return selectItemKey;
            }
        }

        //按下的对象的索引列表
        private List<int> selectIndex = new List<int>();
        /// <summary>
        /// 选中的项的索引

        /// </summary>
        [EditorBrowsable(EditorBrowsableState.Never)]
        public List<int> SelectIndex
        {
            get
            {
                return selectIndex;
            }
        }

        private ImageList itemsIconList = new ImageList();
        /// <summary>
        /// 图标列表
        /// </summary>
        public ImageList ItemsIconList
        {
            get
            {
                return itemsIconList;
            }
            set
            {
                if (itemsIconList != value)
                {
                    itemsIconList = value;
                    iconList.Clear();
                }
            }
        }

        internal bool textCenter = false;
        /// <summary>
        /// 文本是否居中
        /// </summary>
        internal bool TextCenter
        {
            get
            {
                return textCenter;
            }
            set
            {
                textCenter = value;
            }
        }


        //总数据项数

        int dataCount = 0;

        //文本显示属性

        PropertyInfo proTextMember = null;
        //主键属性

        PropertyInfo proValueMember = null;
        //数据源的项列表属性

        PropertyInfo proItemMember = null;
        //当前的聚焦索引,初始为第一个控件

        internal int currIndex = 0;

        //当前页的范围
        int rangeMin = 0;
        int rangeMax = 0;

        //纪录图标
        internal DataListItemIconList iconList = new DataListItemIconList();

        public int exeTime = 0;

        #endregion

        /// <summary>
        /// 项单击事件

        /// </summary>
        public event EventItemClick OnItemClick;

        /// <summary>
        /// 项创建事件

        /// </summary>
        public event EventItemCreateBefore OnItemCreateBefore;

        public DataList()
        {
            //this.AutoScroll = false;
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (pageSize < 1)
            {
                return;
            }

            //子控件数量不等于每页项数情况
            if (this.Controls.Count != pageSize)
            {
                this.Controls.Clear();
                AddItem();
            }
        }

        /// <summary>
        /// 按照每页显示项数添加控件
        /// </summary>
        void AddItem()
        {
            //添加显示控件
            for (int i = 0; i < pageSize; i++)
            {
                DataListItem dataListItem = new DataListItem();
                dataListItem.Name = "dataListItem" + i.ToString();
                dataListItem.Font = this.ItemFont;
                dataListItem.Location = new Point(0, ItemMargin + i * ((this.Height - (pageSize + 1) * ItemMargin) / pageSize + ItemMargin));
                dataListItem.Click += new EventHandler(dataListItem_Click);
                //dataListItem.OnItemCreateBefore += new EventItemCreateBefore(dataListItem_OnItemCreateBefore);
                dataListItem.BackColor = this.ItemBackColor;
                dataListItem.Size = new Size(this.Width, ((this.Height - (pageSize + 1) * ItemMargin) / pageSize));
                dataListItem.TabIndex = i;
                Controls.Add(dataListItem);
            }
        }

        /// <summary>
        /// 控件状态复位

        /// </summary>
        void ItemReset(DataListItem dataListItem)
        {
            dataListItem.Text = "";
            dataListItem.ItemsIconList = null;
            dataListItem.iconList = null;
            dataListItem.dataSource = null;
            dataListItem.Tag = null;
            dataListItem.ItemSelectState = ButtonStateEnum.Up;
            dataListItem.Font = this.ItemFont;
            dataListItem.BackColor = this.itemBackColor;
            dataListItem.IconWidth = 0;
            dataListItem.RightSpace = 0;
            dataListItem.LeftSpace = 0;
            dataListItem.Refresh();
        }

        //void dataListItem_OnItemCreateBefore(DataListItem item)
        //{
        //    if (OnItemCreateBefore != null)
        //        OnItemCreateBefore(item);
        //}

        /// <summary>
        /// 显示数据
        /// </summary>
        public void DataBind()
        {
            int start = System.Environment.TickCount;
            if (pageSize < 1)
            {
                exeTime = System.Environment.TickCount - start;
            }

            if (IsRadio)
            {
                selectIndex.Clear();
                selectItemKey.Clear();
            }
            //数据源为空

            if (DataSource != null)
                proItemMember = DataSource.GetType().GetProperty("Item");
            else
            {
                EmptyData();
                exeTime = System.Environment.TickCount - start;
                return;
            }

            //项的属性为空

            if (proItemMember == null)
            {
                EmptyData();
                exeTime = System.Environment.TickCount - start;
                return;
            }

            //获得总项数

            PropertyInfo proCountMember = DataSource.GetType().GetProperty("Count");
            if (proCountMember != null && Convert.ToInt32(proCountMember.GetValue(DataSource, null)) > 0)
            {
                dataCount = Convert.ToInt32(proCountMember.GetValue(DataSource, null));
            }
            else
            {
                EmptyData();
                exeTime = System.Environment.TickCount - start;
                return;
            }
            //键盘事件
            this.KeyUp -= new KeyEventHandler(DataListItem_KeyUp);
            this.KeyUp += new KeyEventHandler(DataListItem_KeyUp);
            //控件项数不等于每页的项数则添加

            if (this.Controls.Count != pageSize)
            {
                this.Controls.Clear();
                AddItem();
            }

            //获得数据源对象的类型
            Type type = proItemMember.GetValue(DataSource, new object[] { 0 }).GetType();

            //获得属性

            if (DisplayMember != string.Empty && DisplayMember != "")
                proTextMember = type.GetProperty(DisplayMember);
            if (KeyMember != string.Empty && KeyMember != "")
                proValueMember = type.GetProperty(KeyMember);
            //获取总页数

            GetPageCount();
            //显示当前页的数据
            ShowCurrPage();
            this.Focus();
            //if (IsRadio)
            //    ItemGetFocus();
            exeTime = System.Environment.TickCount - start;
        }

        /// <summary>
        /// 显示当前页数据

        /// </summary>
        /// <param name="iPageIndex"></param>
        private void ShowCurrPage()
        {
            //this.SuspendLayout();
            //当前页索引小于1
            if (pageIndex < 1)
                pageIndex = 1;
            else
                if (pageIndex > pageCount)
                    pageIndex = pageCount;
            //获得当前要显示的范围
            GetPageRange(ref rangeMin, ref rangeMax);
            object obj = null;
            DataListItem dataListItem = null;
            for (int i = rangeMin; i <= rangeMax; i++)
            {
                if (i < 0 && i >= dataCount)
                    continue;
                if (i - rangeMin >= this.Controls.Count)
                    continue;
                dataListItem = (DataListItem)this.Controls[i - rangeMin];
                if (dataListItem == null)
                    continue;

                dataListItem.IconIndex = 0;
                dataListItem.Font = this.ItemFont;
                dataListItem.IconWidth = this.iconWidth;
                dataListItem.RightSpace = this.rightSpace;
                dataListItem.LeftSpace = this.leftSpace;
                dataListItem.ItemsIconList = this.ItemsIconList;
                dataListItem.iconList = this.iconList;
                dataListItem.dataSource = proItemMember.GetValue(DataSource, new object[] { i });

                //设置第一个项为选择的项索引
                if (i == rangeMin)
                    selectItem = dataListItem.dataSource;


                if (proTextMember != null)
                {
                    obj = proTextMember.GetValue(proItemMember.GetValue(DataSource, new object[] { i }), null);
                    if (obj != null)
                    {
                        if (proTextMember.PropertyType.Name == "DateTime")
                        {
                            dataListItem.Text = Convert.ToDateTime(obj).GetDateTimeFormats()[90];
                        }
                        else
                        {
                            dataListItem.Text = obj.ToString();
                        }
                    }
                }
                if (proValueMember != null)
                {
                    obj = proValueMember.GetValue(proItemMember.GetValue(DataSource, new object[] { i }), null);
                    if (obj != null)
                    {
                        dataListItem.Tag = obj;
                    }
                }
                //单选时第一项高亮

                if (IsRadio || !selectIndex.Contains(i))
                {
                    if (IsRadio && i == rangeMin + currIndex)
                    {
                        SetItemShowState(dataListItem, ButtonStateEnum.Down);
                    }
                    else
                    {
                        SetItemShowState(dataListItem, ButtonStateEnum.Up);
                    }
                }
                else
                {
                    SetItemShowState(dataListItem, ButtonStateEnum.Down);
                }
            }
            //当本页显示的项数小于控件项数时显示空白控件

            if (rangeMax - rangeMin + 1 < pageSize)
            {
                foreach (Control ctl in this.Controls)
                {
                    if (ctl.GetType().Name == typeof(DataListItem).Name)
                    {
                        dataListItem = (DataListItem)ctl;
                        int ctlIndex = this.Controls.GetChildIndex((DataListItem)dataListItem);
                        if (ctlIndex > rangeMax - rangeMin)
                        {
                            ItemReset(dataListItem);
                        }
                    }
                }
            }
            //this.ResumeLayout(false);
        }

        /// <summary>
        /// 向下翻页
        /// </summary>
        /// <returns>是否最后一页</returns>
        public bool NextPage()
        {
            int start = System.Environment.TickCount;
            if (pageCount <= 1)
            {
                exeTime = System.Environment.TickCount - start;
                return true;
            }
            if (pageIndex == pageCount)
            {
                exeTime = System.Environment.TickCount - start;
                return true;
            }
            else
                pageIndex = pageIndex + 1;
            ShowCurrPage();
            currIndex = 0;
            ItemGetFocus();
            exeTime = System.Environment.TickCount - start;
            if (pageIndex == pageCount)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 向上翻页
        /// </summary>
        /// <returns>是否第一页</returns>
        public bool PreviousPage()
        {
            int start = System.Environment.TickCount;
            if (pageCount <= 1)
            {
                exeTime = System.Environment.TickCount - start;
                return true;
            }
            if (pageIndex == 1)
            {
                exeTime = System.Environment.TickCount - start;
                return true;
            }
            else
                pageIndex = pageIndex - 1;
            ShowCurrPage();
            currIndex = 0;
            ItemGetFocus();
            exeTime = System.Environment.TickCount - start;
            if (pageIndex == 1)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 显示指定的页
        /// </summary>
        /// <param name="pageIndex">页码</param>
        public void ShowPage(int pageIndex)
        {
            //int start = System.Environment.TickCount;
            if (pageIndex > 0 && pageIndex <= pageCount)
            {
                this.pageIndex = pageIndex;
                ShowCurrPage();
                currIndex = 0;
                ItemGetFocus();
                //exeTime = System.Environment.TickCount - start;
                return;
            }
            //exeTime = System.Environment.TickCount - start;
        }

        /// <summary>
        /// 获得总页数

        /// </summary>
        private void GetPageCount()
        {
            if (pageSize >= this.dataCount)
            {
                pageCount = 1;
            }
            else
            {
                if (pageSize > 0)
                    if (this.dataCount % pageSize == 0)
                    {
                        pageCount = this.dataCount / pageSize;
                    }
                    else
                    {
                        pageCount = this.dataCount / pageSize + 1;
                    }
            }
        }


        /// <summary>
        /// 获得当前页的元素范围
        /// </summary>
        /// <param name="iMin"></param>
        /// <param name="iMax"></param>
        private void GetPageRange(ref int iMin, ref int iMax)
        {
            //如果只有一页

            if (pageCount == 1)
            {
                iMin = 0;
                iMax = dataCount - 1;
            }
            //如果不是最后一页或者最后余数为0
            else if (pageIndex != pageCount || this.dataCount % pageSize == 0)
            {
                iMin = (pageIndex - 1) * pageSize;
                iMax = iMin + pageSize - 1;
            }
            //是最后一页而且余数不为0
            else
            {
                iMin = this.dataCount - this.dataCount % pageSize;
                iMax = this.dataCount - 1;
            }
        }

        void DataListItem_KeyUp(object sender, KeyEventArgs e)
        {
            if (isRadio)
            {
                if (e.KeyCode == Keys.Up)
                {
                    if (currIndex == 0)
                        currIndex = rangeMax - rangeMin;
                    else
                        currIndex = currIndex - 1;
                    ItemGetFocus();
                }
                if (e.KeyCode == Keys.Down)
                {
                    if (currIndex == rangeMax - rangeMin)
                        currIndex = 0;
                    else
                        currIndex = currIndex + 1;
                    ItemGetFocus();
                }
                if (e.KeyCode == Keys.Enter)
                {
                    if (OnItemClick != null)
                        OnItemClick((DataListItem)this.Controls[currIndex]);
                }

                selectItem = ((DataListItem)this.Controls[currIndex]).DataSource;

            }
        }

        private void ItemGetFocus()
        {
            if (isRadio)
            {
                DataListItem dataListItem = new DataListItem();
                foreach (Control ctl in this.Controls)
                {
                    if (ctl.GetType().Name == typeof(DataListItem).Name)
                    {
                        dataListItem = (DataListItem)ctl;
                        if (dataListItem.TabIndex > rangeMax - rangeMin)
                            break;
                        if (dataListItem.TabIndex == currIndex)
                        {
                            if (dataListItem.ItemSelectState == ButtonStateEnum.Up)
                            {
                                SetItemShowState(dataListItem, ButtonStateEnum.Down);
                                OpSelectItemList(dataListItem.Tag, true);
                            }
                        }
                        else
                        {
                            if (dataListItem.ItemSelectState == ButtonStateEnum.Down)
                            {
                                SetItemShowState(dataListItem, ButtonStateEnum.Up);
                                OpSelectItemList(dataListItem.Tag, false);
                            }
                        }
                    }
                }
            }
        }

        private void EmptyData()
        {
            if (this.Controls.Count != pageSize)
            {
                this.Controls.Clear();
                AddItem();
            }
            else
            {
                DataListItem dataListItem;
                foreach (Control ctl in this.Controls)
                {
                    if (ctl.GetType().Name == typeof(DataListItem).Name)
                    {
                        dataListItem = (DataListItem)ctl;
                        ItemReset(dataListItem);
                    }
                }
            }
        }

        void dataListItem_Click(object sender, EventArgs e)
        {
            this.Focus();
            if (DataSource == null || proItemMember == null || dataCount == 0)
                return;
            if (((Control)sender).TabIndex > rangeMax - rangeMin)
                return;
            if (IsRadio)
            {

                DataListItem dataListItem = new DataListItem();
                foreach (Control ctl in this.Controls)
                {
                    if (ctl.GetType().Name == typeof(DataListItem).Name)
                    {
                        dataListItem = (DataListItem)ctl;
                        if (dataListItem.TabIndex > rangeMax - rangeMin)
                            break;
                        if (dataListItem.TabIndex == ((DataListItem)sender).TabIndex)
                        {
                            if (dataListItem.ItemSelectState == ButtonStateEnum.Up)
                            {
                                SetItemShowState(dataListItem, ButtonStateEnum.Down);
                                currIndex = dataListItem.TabIndex;
                                OpSelectItemList(dataListItem.Tag, true);
                            }
                        }
                        else
                        {
                            if (dataListItem.ItemSelectState == ButtonStateEnum.Down)
                            {
                                SetItemShowState(dataListItem, ButtonStateEnum.Up);
                                OpSelectItemList(dataListItem.Tag, false);
                            }
                        }
                    }
                }


                selectItem = ((DataListItem)sender).DataSource;


                if (OnItemClick != null)
                    OnItemClick((DataListItem)sender);
            }
            else
            {
                DataListItem dataListItem = (DataListItem)sender;
                if (dataListItem.Tag == null)
                    return;
                int ctlIndex = this.Controls.GetChildIndex((Control)dataListItem);
                int objIndex = (pageIndex - 1) * pageSize + ctlIndex;
                if (dataListItem.ItemSelectState == ButtonStateEnum.Up)
                {
                    SetItemShowState(dataListItem, ButtonStateEnum.Down);
                    if (!selectIndex.Contains(objIndex))
                        selectIndex.Add(objIndex);
                    OpSelectItemList(dataListItem.Tag, true);

                }
                else
                {
                    SetItemShowState(dataListItem, ButtonStateEnum.Up);
                    if (selectIndex.Contains(objIndex))
                        selectIndex.Remove(objIndex);
                    OpSelectItemList(dataListItem.Tag, false);
                }
            }

        }

        void SetItemShowState(DataListItem dataListItem, ButtonStateEnum itemState)
        {
            if (itemState == ButtonStateEnum.Up)
            {
                dataListItem.ForeColor = this.itemForeColor;
                dataListItem.BackColor = this.itemBackColor;
                dataListItem.Font = this.ItemFont;
                dataListItem.ItemSelectState = ButtonStateEnum.Up;
                OpSelectItemList(dataListItem.Tag, false);
            }
            else
            {
                dataListItem.ForeColor = this.selectItemForeColor;
                dataListItem.BackColor = this.selectItemBackColor;
                dataListItem.Font = this.SelectItemFont;
                dataListItem.ItemSelectState = ButtonStateEnum.Down;
                OpSelectItemList(dataListItem.Tag, true);
            }
            if (OnItemCreateBefore != null)
                OnItemCreateBefore(dataListItem);
            //何时刷新整个控件
            //1.更改了图标框的长度时
            //2.项的图标列表为空，适用于最后一页有空项的情况，从显示数据刷为空项

            //3.当有图标列表但是图标显示状态为假的时候，适用于更改图标索引，更改图标索引时图标显示状态置为假
            if (dataListItem.IconWidth != this.iconWidth || dataListItem.ItemsIconList == null || (dataListItem.ItemsIconList != null && !dataListItem.exitsIcon))
                dataListItem.Refresh();
            else
            {
                dataListItem.Invalidate(new Rectangle(dataListItem.IconWidth, 0, this.Width - dataListItem.IconWidth, dataListItem.Height));
                dataListItem.Update();
            }
        }



        void OpSelectItemList(object tag, bool isAdd)
        {
            if (tag != null)
            {
                string key = tag.ToString();
                if (selectItemKey.Contains(key) && !isAdd)
                {
                    selectItemKey.Remove(key);
                }
                if ((!selectItemKey.Contains(key)) && isAdd)
                {
                    if (isRadio)
                        selectItemKey.Clear();
                    selectItemKey.Add(key);
                }
            }
        }

        /// <summary>
        /// 更改指定项的图标索引
        /// </summary>
        /// <param name="ItemIndex">项的索引</param>
        /// <param name="IconIndex">图标索引</param>
        /// <returns>是否成功</returns>
        public bool ChangeItemIconIndex(int ItemIndex, int IconIndex, out int exeTime)
        {
            int start = System.Environment.TickCount;
            //图标列表不为空、图标项数大于0、项索引及图标索引在范围内、更改的索引与原索引不同
            if (itemsIconList != null && itemsIconList.Images.Count > 0 &&
                ItemIndex < this.Controls.Count && ItemIndex >= 0 && IconIndex >= 0 &&
                IconIndex < itemsIconList.Images.Count)
            {
                DataListItem dataListItem = (DataListItem)this.Controls[ItemIndex];
                if (dataListItem.IconIndex != IconIndex)
                {
                    dataListItem.IconIndex = IconIndex;
                    dataListItem.Invalidate(new Rectangle(0, 0, dataListItem.IconWidth, dataListItem.Height));
                    dataListItem.Update();
                    exeTime = System.Environment.TickCount - start;
                    return true;
                }
            }
            exeTime = System.Environment.TickCount - start;
            return false;
        }

    }
    public delegate void EventItemClick(DataListItem item);
    public delegate void EventItemCreateBefore(DataListItem item);
}
